﻿Imports System
Imports System.ComponentModel
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class IDPropertyDescriptor
        Inherits DynamicPropertyDescriptor
        ' Methods
        Friend Sub New(ByVal serviceProvider As IServiceProvider, ByVal actualPropDesc As PropertyDescriptor)
            MyBase.New(serviceProvider, actualPropDesc)
        End Sub

        Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
            Return False
        End Function

        Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
            Dim activity As Activity = [TryCast](component,Activity)
            If (Not activity Is Nothing) Then
                Dim site As ISite = PropertyDescriptorUtils.GetSite(MyBase.ServiceProvider, component)
                If (site Is Nothing) Then
                    Throw New Exception(SR.GetString("General_MissingService", New Object() { GetType(ISite).FullName }))
                End If
                Dim service As IIdentifierCreationService = [TryCast](site.GetService(GetType(IIdentifierCreationService)),IIdentifierCreationService)
                If (service Is Nothing) Then
                    Throw New Exception(SR.GetString("General_MissingService", New Object() { GetType(IIdentifierCreationService).FullName }))
                End If
                Dim identifier As String = [TryCast](value,String)
                service.ValidateIdentifier(activity, identifier)
                DesignerHelpers.UpdateSiteName(activity, identifier)
                MyBase.SetValue(component, value)
            End If
        End Sub

    End Class
End Namespace

